package com.just.springbootmessage.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.just.springbootmessage.rabbitmq.RabbitContent.QUEUE_FANOUT_A;
import static com.just.springbootmessage.rabbitmq.RabbitContent.QUEUE_FANOUT_B;
import static com.just.springbootmessage.rabbitmq.RabbitContent.QUEUE_FANOUT_C;

/**
 * Fanout Exchange 消息广播的模式，不管路由键或者是路由模式，会把消息发给绑定给它的全部队列，如果配置了routing_key会被忽略。
 */
@Configuration
public class FanoutRabbitConfig {
    @Bean
    public Queue AMessage(){
        return new Queue(QUEUE_FANOUT_A);
    }
    @Bean
    public Queue BMessage(){
        return new Queue(QUEUE_FANOUT_B);
    }
    @Bean
    public Queue CMessage(){
        return new Queue(QUEUE_FANOUT_C);
    }
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanoutExchange");
    }

    @Bean
    public Binding bindingExchangeA(Queue AMessage,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(AMessage).to(fanoutExchange);
    }
    @Bean
    public Binding bindingExchangeB(Queue BMessage,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(BMessage).to(fanoutExchange);
    }
    @Bean
    public Binding bindingExchangeC(Queue CMessage,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(CMessage).to(fanoutExchange);
    }
}
